﻿<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="../../../assets/docs.css" rel="stylesheet" type="text/css" media="screen" />
<title>MooTools Documentation - Types/Object.Extras</title>
</head>

<body>
  <div class="doc">
    <div class="methods">
			<h4 class="menu-item"><a href="#Object">Object</a></h4>
<div class="menu-item"><a href="#Object:Object-getFromPath">Object.getFromPath</a></div>
<div class="menu-item"><a href="#Object:Object-cleanValues">Object.cleanValues</a></div>
<div class="menu-item"><a href="#Object:Object-erase">Object.erase</a></div>
<div class="menu-item"><a href="#Object:Object-run">Object.run</a></div>
    </div>
    <div class="l-border r-border span-15 content">
				<h1 id="Object"><a href="#Object">Type: Object</a></h1>

<p class="description">A collection of Object functions.</p>

<h3>Tutorial/Demo</h3>

<ul>
<li><a href="http://www.clientcide.com/wiki/cnet-libraries/03-native/02-hash.extras">Online Tutorial/Demo</a></li>
</ul>
<h3>See Also</h3>

<ul>
<li><a href="../../core/Types/Object.html">Object</a></li>
</ul>
<h2 id="Object:Object-getFromPath"><a href="#Object:Object-getFromPath">Object Function: getFromPath</a></h2>

<p class="description">Returns a value of an object by its path.</p>

<h3>Syntax</h3>

<pre class="javascript">Object.<span class="me1">getFromPath</span><span class="br0">(</span>myObject, path<span class="br0">)</span>;
</pre>

<h3>Arguments</h3>

<ol>
<li>object - (<em>object</em>) The object to search in</li>
<li>path - (<em>string</em>, <em>array</em>) the path to the key for the value you wish to retrieve</li>
</ol>
<h3>Returns</h3>

<ul>
<li>(<em>null</em> or <em>mixed</em>) if the path has no value, <em>null</em> is returned; otherwise the value that corresponds to the path is returned.</li>
</ul>
<h3>Example</h3>

<pre class="javascript">Object.<span class="me1">getFromPath</span><span class="br0">(</span><span class="br0">{</span>
    food: <span class="br0">{</span>
        fruits: <span class="br0">{</span>
            apples: <span class="st0">"red"</span>,
            lemon: <span class="st0">"yellow"</span>
        <span class="br0">}</span>
    <span class="br0">}</span>
<span class="br0">}</span>, <span class="st0">'food.fruits.apples'</span><span class="br0">)</span>; <span class="co1">// 'red'</span>
&nbsp;
Object.<span class="me1">getFromPath</span><span class="br0">(</span><span class="br0">{</span>food: <span class="br0">{</span>pizza: <span class="st0">'yum!!'</span><span class="br0">}</span><span class="br0">}</span>, <span class="br0">[</span><span class="st0">'food'</span>, <span class="st0">'pizza'</span><span class="br0">]</span><span class="br0">)</span>; <span class="co1">// 'yum!!'</span>
</pre>

<h2 id="Object:Object-cleanValues"><a href="#Object:Object-cleanValues">Object Function: cleanValues</a></h2>

<p class="description">Removes values from the object.</p>

<h3>Syntax</h3>

<pre class="javascript">Object.<span class="me1">cleanValues</span><span class="br0">(</span>myObject, method<span class="br0">)</span>;
</pre>

<h3>Arguments</h3>

<ol>
<li>object - (<em>object</em>) The original object that should be cleaned up</li>
<li>method - (<em>function</em>) The function that each value in the Hash is passed. If it returns <code>true</code> the value is kept. Defaults to check if the value <code>!= null</code>.</li>
</ol>
<h3>Returns</h3>

<ul>
<li>(<em>object</em>) - The cleaned object</li>
</ul>
<h3>Example</h3>

<pre class="javascript">Object.<span class="me1">cleanValues</span><span class="br0">(</span><span class="br0">{</span>
    foo: <span class="st0">'bar'</span>,
    something: <span class="st0">'else'</span>,
    missing: <span class="kw2">null</span>
<span class="br0">}</span><span class="br0">)</span>;
&nbsp;
<span class="co1">//remove all values &lt; 0</span>
Object.<span class="me1">cleanValues</span><span class="br0">(</span><span class="br0">{</span>
    a: <span class="nu0">-1</span>,
    b: <span class="nu0">2</span>,
    c: <span class="nu0">0</span>,
    d: <span class="nu0">-5</span>
<span class="br0">}</span>, <span class="kw2">function</span><span class="br0">(</span>value<span class="br0">)</span><span class="br0">{</span>
    <span class="kw1">if</span> <span class="br0">(</span><span class="kw1">typeOf</span><span class="br0">(</span>value<span class="br0">)</span> != <span class="st0">"number"</span><span class="br0">)</span> <span class="kw1">return</span> <span class="kw2">true</span>;
    <span class="kw1">return</span> value &gt; <span class="nu0">0</span>;
<span class="br0">}</span><span class="br0">)</span>;
</pre>

<h2 id="Object:Object-erase"><a href="#Object:Object-erase">Object Function: erase</a></h2>

<p class="description">Deletes a property from the object.</p>

<h3>Syntax</h3>

<pre class="javascript">Object.<span class="me1">erase</span><span class="br0">(</span>object, key<span class="br0">)</span>
</pre>

<h3>Example</h3>

<pre class="javascript"><span class="kw2">var</span> alphabet = <span class="br0">{</span>a: <span class="st0">'a'</span>, b: <span class="st0">'b'</span>, c: <span class="st0">'c'</span><span class="br0">}</span>;
Object.<span class="me1">erase</span><span class="br0">(</span>alphabet, <span class="st0">'b'</span><span class="br0">)</span>;
<span class="co1">// alphabet == {a: 'a', c: 'c'};</span>
</pre>

<h3>Returns</h3>

<ul>
<li>(<em>object</em>) - The object.</li>
</ul>
<h2 id="Object:Object-run"><a href="#Object:Object-run">Object Function: run</a></h2>

<p class="description">Runs all the methods that are values of the object while passing any additional arguments passed to this function.</p>

<h3>Syntax</h3>

<pre class="javascript">Object.<span class="me1">run</span><span class="br0">(</span>object<span class="br0">[</span>, arg1<span class="br0">[</span>, arg2<span class="br0">[</span>, ...<span class="br0">]</span><span class="br0">]</span><span class="br0">]</span><span class="br0">)</span>
</pre>

<h3>Example</h3>

<pre class="javascript"><span class="kw2">var</span> initMyPage = <span class="br0">{</span>
    setupNav: <span class="kw2">function</span><span class="br0">(</span><span class="br0">)</span><span class="br0">{</span>
        <span class="co1">//set up the nav</span>
    <span class="br0">}</span>,
    setupSearch: <span class="kw2">function</span><span class="br0">(</span><span class="br0">)</span><span class="br0">{</span>
        <span class="co1">//set up the search</span>
    <span class="br0">}</span>
<span class="br0">}</span>;
&nbsp;
window.<span class="me1">addEvent</span><span class="br0">(</span><span class="st0">'domready'</span>, <span class="kw2">function</span><span class="br0">(</span><span class="br0">)</span><span class="br0">{</span>
    Object.<span class="me1">run</span><span class="br0">(</span>initMyPage<span class="br0">)</span>;
<span class="br0">}</span><span class="br0">)</span>;
</pre>

<h3>Returns</h3>

<ul>
<li>(<em>object</em>) - The object.</li>
</ul>

    </div>
  </div>
<script type="text/javascript" src="../../../assets/mootools-core-1.3.js"></script>
<script type="text/javascript" src="../../../assets/mootools-more-smoothscroll.js"></script>
<script type="text/javascript" src="../../../assets/doc-assist.js"></script>
</body>
</html>
